/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#pragma once

#include <cassert>
#include <memory>
#include <iostream>

template<class T>
class Singleton
{
public:   
    static void initSingleton()
    {
        assert( Omen::Instance_.get() == 0);
        
        instance_ = std::unique_ptr<T>(new T);
    }

    static T& getSingleton()
    {
        assert( Omen::Instance_.get() != 0);
        
        return *instance_;
    }
    
    static void destroySingleton()
    {
        assert( Omen::Instance_.get() != 0);
        
        instance_.reset();
    }

    virtual ~Singleton()=0;

private:
    
    static std::unique_ptr<T> instance_;
};

template<class T> 
std::unique_ptr<T> Singleton<T>::instance_(0);

template<class T>
Singleton<T>::~Singleton() { }

/*****
 ** Usage of Singleton Class

    class Something : public Singleton<Something>
    {
        friend class Singleton<Something>;
        friend class std::unique_ptr<Something>;
    private:
        Something() { std::wcout << L"created" << std::endl; }
        ~Something() { std::wcout << L"destroyed" << std::endl; }
    };

***/